<!--
 * 档案案卷 table组件
 * :
 * @version: 1.0
 * @author: lakeside hubin_yuan.410@hotmail.com
 * @date: 20120-07-14
 * @LastEditors:
 * @LastEditTime:
 -->
<template>
  <div class="grid_wrapper">
    <el-row class="grid_toolbar" justify="space-between" type="flex">
      <el-button-group>
        <el-tooltip class="item" content="刷新当前数据" effect="dark" placement="right">
          <el-dropdown split-button type="primary" @click="keepStateRefresh" @command="refreshCommand">刷新数据
            <el-dropdown-menu slot="dropdown">
              <el-tooltip class="item" content="重置分页查询数据" effect="dark" placement="right">
                <el-dropdown-item command="specifySearch">重新查询</el-dropdown-item>
              </el-tooltip>
              <el-tooltip class="item" content="清空条件查询数据" effect="dark" placement="right">
                <el-dropdown-item command="initializeRefresh">初始化查询</el-dropdown-item>
              </el-tooltip>
            </el-dropdown-menu>
          </el-dropdown>
        </el-tooltip>
        <el-button v-if="viewMode=='manage'" v-hasPermission="'dossier:archive:add'" icon="el-icon-circle-plus-outline"
                   type="primary"
                   @click="entityCreate">添加
        </el-button>
        <el-button v-if="viewMode=='manage'" v-hasPermission="'dossier:archive:del'" icon="el-icon-delete" type="danger"
                   @click="entryBatchDelete">
          批量删除
        </el-button>
      </el-button-group>
      <el-form v-hasPermission="'dossier:archive:search'" inline>
        <el-form-item>
          <el-input v-model="search.criteria.filter" autocomplete="off" clearable placeholder="支持【】模糊搜索"
                    @change="specifySearch"></el-input>
        </el-form-item>
        <el-form-item prop="remarkNote">
          <dict-option-select v-model="search.criteria.validStatus"
                              :dictField="this.$constants.coreDict.validStatus.key"
                              autocomplete="off" placeholder="有效状态"></dict-option-select>
        </el-form-item>
        <el-button-group>
          <el-button icon="el-icon-search" type="primary" @click="searchMode(true)">高级搜索</el-button>
        </el-button-group>
      </el-form>
    </el-row>
    <el-row class="grid_content">
      <el-col :span="24" class="wrapper">
        <el-table :data="grid.rows" border height="100%" row-key="id" stripe
                  @selection-change="gridMultipleChange" @sort-change="gridSortChange">
          <el-table-column type="selection"/>
          <el-table-column :sortable="grid.sortable" fixed label="聚合层次" prop="aggregateLevel"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" fixed label="档案档号" prop="archivalCode"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" fixed label="档案分类" prop="archiveClassify"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="归档人" prop="archivedBy"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="目录序号" prop="catalogSeqNo"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="门类主键" prop="categoryId"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="组合类型" prop="composeType"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="版权信息" prop="copyright"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="文件种类" prop="documentType"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="紧急层度" prop="emergencyDegree"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="备案年份" prop="filingYear"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="单位全宗号" prop="fondsCode"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="全宗实体号" prop="fondsEntityCode"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="创作者" prop="formedAuthor"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="卷形成开始时间" prop="formedBeginDate"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="卷形成结束时间" prop="formedEndDate"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="文件形成组织" prop="formedOrganize"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="文件形成时间" prop="formedDate"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="发文编号" prop="issuedNumber"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="题名" prop="mainTitle"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="主题词" prop="mainWord"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="稿本" prop="manuscriptType"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="载体位置" prop="mediumLocation"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="载体编号" prop="mediumNumber"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="载体类型" prop="mediumType"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="页序号" prop="pageSeqNo"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="文件页数" prop="pageSize"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="人物" prop="peoples" show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="件序号" prop="pieceSeqNo"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="文件件数" prop="pieceSize"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="归档日期" prop="archivedDate"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="地点" prop="place" show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="封存盒号" prop="sealBoxNumber"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="封存位置" prop="sealStorageLocation"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="保密等级" prop="secretLevel"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="保管期限" prop="storagePeriod"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="主题" prop="subject" show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="卷序号" prop="volumeSeqNo"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段01" prop="extField01"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段02" prop="extField02"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段03" prop="extField03"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段04" prop="extField04"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段05" prop="extField05"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段06" prop="extField06"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段07" prop="extField07"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段08" prop="extField08"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段09" prop="extField09"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段10" prop="extField10"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段11" prop="extField11"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段12" prop="extField12"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段13" prop="extField13"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段14" prop="extField14"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段15" prop="extField15"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="扩展字段16" prop="extField16"
                           show-overflow-tooltip></el-table-column>
          <el-table-column :sortable="grid.sortable" label="上级卷宗主键" prop="parentDossierId"
                           show-overflow-tooltip></el-table-column>
          <!--<el-table-column prop="createdByName" show-overflow-tooltip label="创建者"></el-table-column>
          <el-table-column prop="createdDate" show-overflow-tooltip label="创建时间"></el-table-column>
          <el-table-column prop="modifiedByName" show-overflow-tooltip label="最后修改者"></el-table-column>
          <el-table-column prop="modifiedDate" show-overflow-tooltip label="最后修改时间"></el-table-column>
          <el-table-column prop="remarkNote" show-overflow-tooltip label="备注描述"></el-table-column>-->
          <el-table-column label="有效状态" prop="validStatusName"></el-table-column>
          <el-table-column align="center" fixed="right" label="操作" width="250">
            <template slot-scope="scope">
              <el-button-group>
                <el-button icon="el-icon-document" @click="entryDetail(scope.row)">详情</el-button>
                <el-button v-if="viewMode=='manage'" v-hasPermission="'dossier:archive:edit'" icon="el-icon-edit"
                           type="primary"
                           @click="entryModify(scope.row)">编辑
                </el-button>
                <el-button v-if="viewMode=='manage'" v-hasPermission="'dossier:archive:del'" icon="el-icon-delete"
                           type="danger"
                           @click="entityDelete(scope.row.key)">删除
                </el-button>
              </el-button-group>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    <el-row class="grid_pagination">
      <el-col :span="24">
        <el-pagination :current-page="grid.page" :page-size="grid.size"
                       :page-sizes="grid.pageSizes" :total="grid.total"
                       background layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChange"
                       @current-change="pageNumChange">
        </el-pagination>
      </el-col>
    </el-row>

    <el-dialog v-dialogDrag :visible.sync="search.visible" title="高级搜索" top="5vh" width="80%">
      <dossierArchiveSearch ref="dossierArchiveSearch" v-model="search"></dossierArchiveSearch>
      <span slot="footer" class="dialog-footer">
                <el-button @click="searchMode(false)">取 消</el-button>
                <el-button @click="searchReset(true)">重置</el-button>
                <el-button type="primary" @click="searchSubmit">搜索</el-button>
            </span>
    </el-dialog>
    <el-dialog v-dialogDrag :title="form.title" :visible.sync="form.visible" top="5vh" width="80%">
      <dossierArchiveForm ref="dossierArchiveForm" v-model="form"></dossierArchiveForm>
      <span slot="footer" class="dialog-footer">
                <el-button v-if="!form.editable" type="text" @click="formMode(true,'编辑',true)">编辑</el-button>
                <el-button v-if="!form.editable" @click="formMode(false)">关闭</el-button>
                <el-button v-if="form.editable" @click="formMode(false)">取 消</el-button>
                <el-button v-if="form.editable" type="primary" @click="formSubmit">保存</el-button>
           </span>
    </el-dialog>
  </div>
</template>

<script>
import *  as dossierArchiveApi from '../apis/archive'
import {api_mixin, form_mixin, grid_mixin, search_mixin} from "@/mixins";
import DossierArchiveForm from "./components/form"
import DossierArchiveSearch from "./components/search"
import DictOptionSelect from "@/views/system/components/DictOptionSelect";

export default {
  name: "dossierArchiveGrid",
  props: {
    viewMode: {type: String, default: "manage"},
    parentData: {},
  },
  components: {DictOptionSelect, DossierArchiveForm, DossierArchiveSearch},
  mixins: [api_mixin, form_mixin, search_mixin, grid_mixin],
  data() {
    return {}
  },
  activated() {
    if (this.$route.meta.keep.state) {
      this.keepStateRefresh()
    } else {
      this.initializeRefresh()
    }
  },
  created() {
    this.gridLoadRefresh()
  },
  watch: {
    parentData() {
      this.initializeRefresh()
    },
  },
  methods: {

    /**创建实体*/
    entityCreate(data) {
      /*if(this.parentData&&!this.parentData['id']){
          this.$message.warning('请先选择父级字段！')
          return
      }*/
      this.formMode(true, "添加", true, {
        ...data, validStatus: this.$constants.coreDict.validStatus.enum.enabled.value,
        parentId: this.parentData && this.parentData['id'] || ''
      })
    },
    /**搜索提交*/
    searchSubmit() {
      this.$refs.dossierArchiveSearch.validate((valid) => {
        if (valid) {
          this.searchMode(false)
          this.specifySearch()
        } else {
          this.$message.error('数据校验失败,请修改后再次查询！')
        }
      })

    },
    /**表单提交*/
    formSubmit() {
      this.$refs.dossierArchiveForm.validate((valid) => {
        if (valid) {
          this.entitySave(this.$refs.dossierArchiveForm.form.entry)
        } else {
          this.$message.error('数据校验失败,请修改后再次提交！')
        }
      }).catch(() => {
      })
    },
    /**实体保存*/
    entitySave(entry) {
      dossierArchiveApi.save(entry).then(response => {
        this.responseHandle(response, "保存").then(() => {
          this.form.visible = false
          this.gridLoadRefresh();
        })
      }).catch(() => {
      })
    },
    /**实体删除*/
    entityDelete(idArr) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示',
          {confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'}
      ).then(() => {
        dossierArchiveApi.remove({idArr: idArr}, {deleteMode: this.$constants.coreDict.deleteMode.enum.physics.value}).then(response => {
          this.responseHandle(response, "删除").then(() => {
            this.gridLoadRefresh();
          })
        })
      }).catch(() => {
      })
    },
    /**刷新表格数据*/
    gridLoadRefresh() {
      if (this.parentData && this.parentData['id']) {
        this.search.criteria.parentId = this.parentData['id'] || ''
      }
      const params = {page: this.grid.page, size: this.grid.size, ...this.search.criteria}
      dossierArchiveApi.page(params).then(response => {
        this.responseHandle(response, "刷新数据").then((result) => {
          const {content: rows, totalElements: total} = result
          this.grid.rows = rows || []
          this.grid.total = total || 0
        })
      }).catch(() => {
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
